package com.ciaojian.core.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ciaojian.core.model.User;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author Atlakyn
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {



    /**
     * 根据用户id获取昵称
     *
     * @param id 用户id
     * @return 用户昵称
     */
    @Select("SELECT nickName FROM d_user WHERE id = #{id} ")
    String getNickNameById(@Param("id") Integer id);

    List<Map<String, Integer>> getCustomerTypeRateOfConsumer(@Param("storeId") Integer storeId,
                                                             @Param("beginDate") Date beginDate,
                                                             @Param("endDate") Date endDate);

    /**
     * 获取消费用户性别比例
     *
     * @param storeId   门店Id
     * @param beginDate 开始时间
     * @param endDate   结束时间
     * @return 消费用户性别比例
     */
    List<Map<String, String>> getGenderRateOfConsumer(@Param("storeId") Integer storeId,
                                                      @Param("beginDate") Date beginDate,
                                                      @Param("endDate") Date endDate);

    /**
     * 根据 id 获取 openId
     *
     * @param id 用户id
     * @return openId
     */
    @Select("SELECT openid FROM d_user WHERE id = #{id} ")
    String getOpenIdById(Integer id);

    @Select("SELECT dy_openid FROM d_user WHERE id = #{id} ")
    String getDyOpenIdById(Integer id);

    /**
     * 根据 unionId 更新
     *
     * @param user user 对象
     */
    @Update("UPDATE d_user SET avatarUrl = #{avatarUrl}, nickName = #{nickName}, openid = #{openid} WHERE unionid = #{unionid}")
    void updateUserByUnionId(User user);


    @Select("SELECT * FROM d_user WHERE unionId = #{unionId} LIMIT 0,1")
    User getDUserList(String unionId);

    @Insert("INSERT INTO d_user(openid,unionid,nickName,avatarUrl,add_time,telphone,is_upload,is_distribution,group_id,p1,p2,p3,balance,balance_total,integral,LEVEL) \n" +
            "VALUES(#{openid},#{unionid},#{nickName},#{avatarUrl},#{addTime},'0',0,0,0,0,0,0,0,0,0,0)")
    int getAddWxUser(User user);

    /**
     * 根据用户 id 获取标签字符串
     *
     * @param id 用户 id
     * @return 用户的标签字符串
     */
    @Select("SELECT user_labels FROM d_user WHERE id = #{id}")
    String getLabelsById(@Param("id") Integer id);


    @Select("SELECT add_time FROM d_user WHERE id = #{userId}")
    Date getAddTime(@Param("userId") Integer userId);

    @Select("SELECT * FROM d_user LIMIT #{pigeSide},#{side}")
    List<User> selectLists(@Param("pigeSide") int pigeSide, @Param("side") int side);


    @Select("SELECT * FROM d_user_copy1 where telphone like '%\\_%' LIMIT #{pigeSide},#{side}")
    List<User> selectListsuserCopy1(@Param("pigeSide") int pigeSide, @Param("side") int side);


    @Select("SELECT max(id) FROM d_user where id like '1%'")
    Integer maxId();
}
